package com.ruoyi.web.controller.baodao.controller;

import com.ruoyi.baodao.vo.AgeCount;
import com.ruoyi.baodao.vo.AmountCount;
import com.ruoyi.baodao.vo.GenderCount;
import com.ruoyi.baodao.vo.HourCount;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.web.controller.baodao.service.StatementService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/baodao/statement")
public class StatementController {
    @Autowired
    StatementService statementService;

    private String prefix = "baodao/statement";

    @RequestMapping("/echartsdemo")
    public String echartsdemo(){
        return prefix + "/echartsdemo";
    }

    @RequestMapping("/ca1")
    public String ca1(){
        return prefix + "/ca1";
    }

    @RequestMapping("/ca2")
    public String ca2(){
        return prefix + "/ca2";
    }

    @RequestMapping("/ta1")
    public String ta1(){
        return prefix + "/ta1";
    }

    @RequestMapping("/ta2")
    public String ta2(){
        return prefix + "/ta2";
    }
    // 日客群分析
    @RequestMapping("/day")
    public String day(){
        return prefix + "/day";
    }

    // 时间段客群分析
    @RequestMapping("/days")
    public String days(){
        return prefix + "/days";
    }

    @PostMapping("/queryHourCount")
    @ResponseBody
    public AjaxResult queryHourCount(String startTime,String endTime){
        log.info("查询条件：" + startTime + ' ' + endTime);
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
       // List<HourCount> hourCountList = statementService.queryHourCount(null,null,null,null);
        // 生客
        List<HourCount> hourCounts1 = statementService.queryHourCount(sysUser.getDept().getDeptName(),startTime,endTime,"1");
        log.info("24小时生客统计:" + hourCounts1.toString());
        // 熟客
        List<HourCount> hourCounts2 = statementService.queryHourCount(sysUser.getDept().getDeptName(),startTime,endTime,"2");
        log.info("24小时熟客统计：" + hourCounts2.toString());
        Map<String,List> map = new HashMap<>();
        map.put("stranger",hourCounts1);
        map.put("regular",hourCounts2);

        return AjaxResult.success(map);
    }


    @PostMapping("/queryGenderCount")
    @ResponseBody
    public AjaxResult queryGenderCount(String startTime,String endTime){
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
        List<GenderCount> genderCounts = statementService.queryGenderCount(sysUser.getDept().getDeptName(),startTime,endTime);
        return AjaxResult.success(genderCounts);
    }

    @PostMapping("/queryAgeCount")
    @ResponseBody
    public AjaxResult queryAgeCount(String startTime,String endTime){
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
        List<AgeCount> ageCounts = statementService.queryAgeCount(sysUser.getDept().getDeptName(),startTime,endTime);
        return AjaxResult.success(ageCounts);
    }

    @PostMapping("/queryAmountCountByGender")
    @ResponseBody
    public AjaxResult queryAmountCountByGender(String startTime,String endTime){
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
        HashMap<String,HashMap> result = statementService.queryAmountCountByGender(sysUser.getDept().getDeptName(),startTime,endTime);
        return AjaxResult.success(result);
    }

    @PostMapping("/queryAmountCountByAge")
    @ResponseBody
    public AjaxResult queryAmountCountByAge(String startTime,String endTime){
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
        HashMap<String,HashMap> result = statementService.queryAmountCountByAge(sysUser.getDept().getDeptName(),startTime,endTime);
        return AjaxResult.success(result);
    }




}
